from django.db import models

TERMS = zip(
    range(1,9),
    ('1A', '1B', '2A', '2B', '3A', '3B', '4A', '4B')
)

class Course(models.Model):
    department = models.CharField(max_length=15)
    course_code = models.CharField(max_length=6)
    short_form = models.CharField(max_length=16, blank=True)
    full_name = models.CharField(max_length=250)
    cse_a = models.PositiveIntegerField(default=0)
    cse_b = models.PositiveIntegerField(default=0)
    cse_c = models.PositiveIntegerField(default=0)
    cse_d = models.PositiveIntegerField(default=0)
    te_math = models.DecimalField(max_digits=4, decimal_places=2, default=0)
    te_sci = models.DecimalField(max_digits=4, decimal_places=2, default=0)
    te_engsci = models.DecimalField(max_digits=4, decimal_places=2, default=0)
    te_engdes = models.DecimalField(max_digits=4, decimal_places=2, default=0)
    core_course = models.BooleanField()
    default_term = models.PositiveIntegerField(choices=TERMS, blank=True, null=True)
    offered_fall = models.BooleanField()
    offered_winter = models.BooleanField()
    offered_spring = models.BooleanField()
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def cse(self):
        if self.cse_a > 0:
            return "A"
        elif self.cse_b > 0:
            return "B"
        elif self.cse_c > 0:
            return "C"
        elif self.cse_d > 0:
            return "D"
        else:
            return "None"

    def __unicode__(self):
        return self.department + self.course_code



